import PlayerDataMgr from "./PlayerDataMgr";

const {ccclass, property, requireComponent} = cc._decorator;

@ccclass
@requireComponent(cc.Toggle)
export default class EffectToggle extends cc.Component {
    
    private thisToggle: cc.Toggle = null;

    onLoad () {
        var clickEventHandler = new cc.Component.EventHandler();
        clickEventHandler.target = this.node; // 这个 node 节点是你的事件处理代码组件所属的节点
        clickEventHandler.component = "EffectToggle";// 这个是代码文件名
        clickEventHandler.handler = "callback";
        clickEventHandler.customEventData = "";

        this.thisToggle = this.node.getComponent(cc.Toggle);
        this.thisToggle.clickEvents.push(clickEventHandler);
        this.thisToggle.isChecked = (PlayerDataMgr.getInstance().effect_on != 0);
    }

    callback() {
        console.log(`EffectToggle:${this.thisToggle.isChecked}`);
        PlayerDataMgr.getInstance().switchEffect(this.thisToggle.isChecked? 0: 1);
    }
}
